perm filename FIND[E,ALS] blob
sn#187937 filedate 1975-11-26 generic text, type C, neo UTF8
COMMENT ā VALID 00002 PAGES
C REC PAGE DESCRIPTION
C00001 00001
C00002 00002 A fast find command using Gosper's scheme
C00007 ENDMK
Cā;
;A fast find command using Gosper's scheme
PLONG: 0 ;Pattern length
FTABLE: BLOCK 177 ;To hold pointer indexing commands
JRST RELOAD ;To reload buffer and test for end of file
FOLD: BLOCK 32 ;Space to hold last 26 words from previous load
FBUF: BLOCK 200 ;Loaded with record from file
REPEAT 32,<-2> ;Guard for possible pattern length of 128 chars.
FLOOP: ILDB C,A ;Get next character from file
XCT @FTABLE(C)
;Code from this list is used for storing in FTABLE
;It is accessed indexed as to the distance from the last char of the pattern to the
;last occurance of the character in the pattern as identified by the position
;in FTABLE that is being loaded. All characters not in the pattern are assumed
;to be at the pattern-length distance.
FLOAD: JRST BACK1 ;0 Found last char match
JRST FLOOP ;1 Get next character and start at FLOOP
JRST FLOAD1 ;2 Index over 1 and then get next
JRST FLOAD2 ;3 Jump over 2 and then get next
JRST FLOAD3 ;4 Jump over 3 and then get next
JRST FLOAD5 ;5 Jump over 4 and then get next
FLOAD5: AOJA A,FLOOP ;6 Jump over 5 and then get next
AOJA A,FLOAD1 ;7
AOJA A,FLOAD2 ;10
AOJA A,FLOAD3 ;11
AOJA A,FLOAD4 ;12
AOJA A,FLOAD5 ;13
JRST FLOAD5 ;16
JRST FLOAD6 ;17
JRST FLOAD7 ;20
JRST FLOA10 ;21
JRST FLOA11 ;22
JRST FLOA12 ;23
JRST FL0A13 ;24
JRST FLOA14 ;25
FLOAD1: IBP A
JRST FLOOP
FLOAD2: SUB A,[160000,,0]
JUMPG A,FLOOP
ADDI A,[430000,,1]
JRST FLOOP
FLOAD3: SUB A,[250000,,0]
JUMPG A,FLOOP
ADDI A,[430000,,1]
JRST FLOOP
FLOAD4: SUB A,[340000,,0]
JUMPG A,FLOOP
ADDI A,[430000,,1]
JRST FLOOP
;Code to compute addition for dirtance greater than 13
FLOAD6: ADDI A,[-70000,,2]
JUMPG A,FLOOP
ADDI A,[430000,,1]
JRST FLOOP
FLOAD7: ADDI A,[-160000,,2]
JUMPG A,FLOOP
ADDI A,[430000,,1]
JRST FLOOP
FLOA10: ADDI A,[-250000,,2]
JUMPG A,FLOOP
ADDI A,[430000,,1]
JRST FLOOP
FLOA11: ADDI A,[-340000,,2]
JUMPG A,FLOOP
ADDI A,[430000,,1]
JRST FLOOP
FLOA12: ADDI A,3
JRST FLOOP
;Code to compute value to store in FTABLE
COMP: MOVNI T,PNUM
HRLZS T
MOVE A,[440700,,PATTER]
MOVE TT,T
COMP1: ILDB C,A
MOVE B,A
IBP B
COMP2: ILDB D,B
CAMN D,C
JRST COMP3
AOBJN TT,COMP2
MOVE B,LIST(TT)
MOVEM B,FTABLE(C)
JRST COMP1
COMP3: MOVE T,TT
MOVE A,D
JRST COMP1
ZZZ:
Code to preload code referenced by FTABLE for all characters not in PATTERN
MOVE T,[JRST NOTIN]
MOVEM T,FTABLE
MOVEM A,[FTABLE,,FTABLE+1]
BLT A,FTABLE+177
;Code to compute value to be used by code NOTIN
MOVE T,PLONG
SUBI T,1 ;There will always be an ILDB
IDIVI T,5
IMULI TT,7
LSH TT,26
SUB T,TT
MOVEM T,PSHIFT
;Code referenced when char. is not in PATTERN
NOTIN: ADD A,PSHIFT
JUMPG A,FLOOP
ADDI A,[430000,,1]
JRST FLOOP